//
//  NQRecord.m
//  ZLFastDoctor
//
//  Created by 李岚清 on 16/5/25.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "NQRecord.h"

@implementation NQRecord

//创建模型类方法
+ (NQRecord *)recordWithsickType:(NSString *)sickType sickDetail:(NSString *)sickDetail
                     sickDesTags:(NSArray *)sickDesTags sickDescribe:(NSString *)sickDescribe picArr:(NSMutableArray *)picArr firstImage:(UIImage *)firstImage postTime:(NSString *)postTime{
    NQRecord *record = [[NQRecord alloc] init];
    record.sickType = sickType;
    record.sickDetail = sickDetail;
    record.sickDesTags = sickDesTags;
    record.sickDescribe = sickDescribe;
    record.picArr = picArr;
    record.firstImage = firstImage;
    record.postTime = postTime;
    return  record;
}

#pragma mark - 自定义归档
//归档
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.sickType forKey:@"sickType"];
    [aCoder encodeObject:self.sickDetail forKey:@"sickDetail"];
    [aCoder encodeObject:self.sickDesTags forKey:@"sickDesTags"];
    [aCoder encodeObject:self.sickDescribe forKey:@"sickDescribe"];
    [aCoder encodeObject:self.picArr forKey:@"picArr"];
    [aCoder encodeObject:self.firstImage forKey:@"firstImage"];
    [aCoder encodeObject:self.postTime forKey:@"postTime"];
}

//解档
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super init]) {
        self.sickType = [aDecoder decodeObjectForKey:@"sickType"];
        self.sickDetail = [aDecoder decodeObjectForKey:@"sickDetail"];
        self.sickDesTags = [aDecoder decodeObjectForKey:@"sickDesTags"];
        self.sickDescribe = [aDecoder decodeObjectForKey:@"sickDescribe"];
        self.picArr = [aDecoder decodeObjectForKey:@"picArr"];
        self.firstImage = [aDecoder decodeObjectForKey:@"firstImage"];
        self.postTime = [aDecoder decodeObjectForKey:@"postTime"];
    }
    return self;
}

#pragma mark - 归档/解档
//读
+ (NSArray <NQRecord *>*)readRecordArr{
    //1.获取沙盒路径
    NSString *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
    //2.拼接存储路径
    NSString *filePath = [path stringByAppendingPathComponent:@"recordInfo.plist"];
    //3.解档,获取模型数组
    NSArray *recordArr = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
    return recordArr;
}

//写
+ (void)saveRecordArr:(NSArray <NQRecord *>*)array{
    //1.获取沙盒路径
    NSString *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
    //2.拼接存储路径
    NSString *fliePath = [path stringByAppendingPathComponent:@"recordInfo.plist"];
    //3.归档
    [NSKeyedArchiver archiveRootObject:array toFile:fliePath];
}

@end
